package com.netsmart.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.netsmart.dto.base.BaseDto;
import com.netsmart.dto.base.ResponseDate;
import com.netsmart.enums.HttpEnum;
import com.netsmart.enums.StateEnum;
import com.netsmart.service.LoginService;

@Controller
@RequestMapping("/sys/account/")
public class LoginController extends BaseDto {

    @Autowired
    LoginService loginService;

    @RequestMapping(value = "login", method = RequestMethod.POST, produces = { "application/json;charset=UTF-8" })
    @ResponseBody
    public String loginAccount(@RequestBody String json) {
        try {
            System.out.println(json);
            return loginService.login(json);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return gson.toJson(new ResponseDate<>(HttpEnum.OK.getState(), StateEnum.INNER_ERROR.getState(), "网络异常"));
        }
    }
    
    
    /**
      * register
      * TODO 注册用户
    
      * @author 创建人-qiaowei
      * @date 2019年1月23日 下午3:50:43
      * @return String    返回类型
      * @throws
     */
    @RequestMapping(value = "register", method = RequestMethod.POST, produces = { "application/json;charset=UTF-8" })
    @ResponseBody
    public String register(@RequestBody String json) {
        try {
            System.out.println(json);
            return loginService.register(json);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return gson.toJson(new ResponseDate<>(HttpEnum.OK.getState(), StateEnum.INNER_ERROR.getState(), "网络异常"));
        }
    }
    
    /**
      * loginCount
      * TODO登录时统计语句信息
    
      * @author 创建人-qiaowei
      * @date 2019年1月23日 下午4:47:27
      * @return String    返回类型
      * @throws
     */
    @RequestMapping(value = "loginCount", method = RequestMethod.POST, produces = { "application/json;charset=UTF-8" })
    @ResponseBody
    public String loginCount(@RequestBody String json) {
        try {
            System.out.println(json);
            return loginService.loginCount(json);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return gson.toJson(new ResponseDate<>(HttpEnum.OK.getState(), StateEnum.INNER_ERROR.getState(), "网络异常"));
        }
    }
    
    /**
      * selectSentence
      * TODO根据吐槽类型获取吐槽
    
      * @author 创建人-qiaowei
      * @date 2019年1月23日 下午4:52:57
      * @return String    返回类型
      * @throws
     */
    @RequestMapping(value = "selectSentence", method = RequestMethod.POST, produces = { "application/json;charset=UTF-8" })
    @ResponseBody
    public String selectSentence(@RequestBody String json) {
        try {
            System.out.println(json);
            return loginService.selectSentence(json);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return gson.toJson(new ResponseDate<>(HttpEnum.OK.getState(), StateEnum.INNER_ERROR.getState(), "网络异常"));
        }
    } 
    
    @RequestMapping(value = "selectAllSentence", method = RequestMethod.POST, produces = { "application/json;charset=UTF-8" })
    @ResponseBody
    public String selectAllSentence() {
        try {
            return loginService.selectSentence();
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return gson.toJson(new ResponseDate<>(HttpEnum.OK.getState(), StateEnum.INNER_ERROR.getState(), "网络异常"));
        }
    } 
    
    /**
      * insertSentence
      * TODO 发表吐槽
    
      * @author 创建人-qiaowei
      * @date 2019年1月23日 下午4:48:05
      * @return String    返回类型
      * @throws
     */
    @RequestMapping(value = "insertSentence", method = RequestMethod.POST, produces = { "application/json;charset=UTF-8" })
    @ResponseBody
    public String insertSentence(@RequestBody String json) {
        try {
            System.out.println(json);
            return loginService.insertSentence(json);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return gson.toJson(new ResponseDate<>(HttpEnum.OK.getState(), StateEnum.INNER_ERROR.getState(), "网络异常"));
        }
    }
    
}
